package org.dromara.business.utils;

import cn.hutool.core.util.NumberUtil;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class ChinesePhoneNumberGenerator {

    private static final List<String> PREFIXES = List.of(
        "130", "131", "132", "133", "134", "135", "136", "137", "138", "139",
        "145", "147", "149",
        "150", "151", "152", "153", "155", "156", "157", "158", "159",
        "165", "166", "167", "168",
        "170", "171", "172", "173", "174", "175", "176", "177", "178",
        "180", "181", "182", "183", "184", "185", "186", "187", "188", "189",
        "191", "198", "199"
    );

    private static final ThreadLocalRandom RANDOM = ThreadLocalRandom.current();

    /**
     * 生成单个中国手机号码
     */
    public static String generate() {
        String prefix = PREFIXES.get(RANDOM.nextInt(PREFIXES.size()));
        String suffix = IntStream.range(0, 8)
                               .mapToObj(i -> String.valueOf(RANDOM.nextInt(10)))
                               .collect(Collectors.joining());
        return prefix + suffix;
    }

    /**
     * 批量生成中国手机号码
     * @param count 要生成的数量
     * @return 手机号码列表
     */
    public static List<String> generate(int count) {
        return IntStream.range(0, count)
                      .mapToObj(i -> generate())
                      .collect(Collectors.toList());
    }

    /**
     * 验证手机号码是否有效
     * @param phoneNumber 手机号码
     * @return 是否有效
     */
    public static boolean isValid(String phoneNumber) {
        if (phoneNumber == null || phoneNumber.length() != 11) {
            return false;
        }

        // 检查开头
        String prefix = phoneNumber.substring(0, 3);
        if (!PREFIXES.contains(prefix)) {
            prefix = phoneNumber.substring(0, 2);
            if (!PREFIXES.contains(prefix)) {
                return false;
            }
        }

        // 检查剩余部分是否为数字
        return phoneNumber.chars().allMatch(Character::isDigit);
    }

    public static void main(String[] args) {
       LocalDateTime localDateTime = LocalDateTime.of(2025, 9, 6, 0, 0);
        if (localDateTime.isAfter(LocalDateTime.now())) {
            System.out.println("===");
        }
    }
}
